package com.cskaoyan;

import com.cskaoyan.bean.Car;
import com.cskaoyan.factory.InstanceFactory;
import com.cskaoyan.factory.StaticFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author stone
 * @date 2022/04/25 14:03
 */
public class FactoryTest2 {


    @Test
    public void mytest1() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml");
        //NoUniqueBeanDefinitionException
        //expected single matching bean but found 2: carFromStaticFactory,carFromInstanceFactory
        //Car car = applicationContext.getBean(Car.class);

        Car car1 = applicationContext.getBean("carFromStaticFactory", Car.class);
        Car car2 = applicationContext.getBean("carFromInstanceFactory", Car.class);
        System.out.println(car1);
        System.out.println(car2);

        Car bean = (Car) applicationContext.getBean("carFromFactoryBean");
        System.out.println(bean);
    }

    @Test
    public void mytest2() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml");

    }


}
